<?php
/*
<Controller Information> 
Author: Naseer Ahmad
Date: 20-10-2011
Last Updated on:
*/

class settingsController extends appController
{
	function index()
	{
		
		$options = $this -> settings -> _getOptions(array("siteLogo", "siteBanner", "googleAdsTop"));
		$this -> set("options", $options);
		
		$this -> set("cmd", $this->data['cmd']);
		
		$this -> render("Admin Settings");
	}
	
	function updateSettings(){
		$oldOptions = $this -> settings -> _getOptions(array("siteLogo", "siteBanner", "googleAdsTop"));
		$newOptions = array("googleAdsTop"	=> $this->data['googleAdsTop']);
		
		if($this->file['logo']['error']==0){	////// logo successfully uploaded
			$newOptions['siteLogo'] = $this -> uploadFile(
												$this -> file['logo'],
								 				'images/logos', 
								 				"",
												$oldOptions['siteLogo']);
		}

		if($this->file['banner']['error']==0){	////// banner successfully uploaded
			$newOptions['siteBanner'] = $this -> uploadFile(
												$this -> file['banner'],
								 				'images/banners', 
								 				"",
												$oldOptions['siteBanner']);
		}
		
		$rs = $this -> settings -> _saveOptions($newOptions);
		if($rs) $cmd ="Settings Successfully Updated"; else $cmd ="Settings Not Updated";
		$rdArray=array("page"	=> "settings",
						"cmd"	=> $cmd);
		$this -> redirect($rdArray);
	}
	
}
?>